﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace InfoSite.Tools
{
	public class SiteMapHelper
	{
		public static SiteMapNode GetCurrentNode(SiteMapNode current)
		{
			if (current == null)
				return null;
			
			if (Equals(SiteMap.RootNode, current))
				return current;

			if (SiteMap.RootNode.ChildNodes.Contains(current))
				return current;

			if (SiteMap.RootNode.ChildNodes.Cast<SiteMapNode>().Any(childNode => childNode.ChildNodes.Contains(current)))
			{
				return current;
			}

			return GetCurrentNode(current.ParentNode);
		}
	}
}
